from django import forms
from .models import *
from blog.models import BlogComment


class BlogForm(forms.Form):
    title = forms.CharField(max_length=100,min_length=2,error_messages={
        'required': "标题不能为空",
        'max_length': "标题字符为2-100个字符",
        'min_length': "标题字符为2-100个字符",
    })
    content = forms.CharField(widget=forms.Textarea, max_length=5000,min_length=2,error_messages={
        'required': "内容不能为空",
        'max_length': "内容字符为2-5000个字符",
        'min_length': "内容字符为2-5000个字符",
    })
    category = forms.IntegerField()

class BlogCommentForm(forms.Form):
    content = forms.CharField()
    blog_id = forms.IntegerField()
    def clean_content(self):
        content = self.cleaned_data['content']
        if not content:
            raise forms.ValidationError("评论不能为空")
        return content

